package com.Practice.estore1;
import java.util.Set;
import java.util.HashSet;
public class Product {
    private final String id;
    private final String name;
    private final double price;
    private final int stock;
    private final Set<String> tags; // 新增标签属性

    // 修改构造函数
    public Product(String id, String name, double price, int stock) {
        this(id, name, price, stock, new HashSet<>());
    }

    public Product(String id, String name, double price, int stock, Set<String> tags) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.stock = stock;
        this.tags = (tags != null) ? tags : new HashSet<>();
    }

    public double getPrice() { return price; }

    // 重写 toString 方法，包含标签信息
    @Override
    public String toString() {
        String baseInfo = String.format("ID: %s | 名称: %s | 价格: %.2f | 库存: %d",
                id, name, price, stock);
        if (tags != null && !tags.isEmpty()) {
            return baseInfo + " | 标签: " + tags;
        }
        return baseInfo;
    }
}
